package com.yuneec.fly.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.TextView;

import com.yuneec.fly.R;

/**
 * Created by zd.zhang on 2016/6/15.
 */
public class RightImgTextView extends TextView {
    public RightImgTextView(Context context) {
        super(context);
    }

    public RightImgTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public RightImgTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        Drawable[] drawables = getCompoundDrawables();
        if (drawables != null && drawables[2] != null) {
            TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ImageOption);
            int width = a.getDimensionPixelOffset(R.styleable.ImageOption_imgWidth, 15);
            int height = a.getDimensionPixelOffset(R.styleable.ImageOption_imgHeight, 15);
            a.recycle();
            drawables[2].setBounds(0, 0, width, height);
            setCompoundDrawables(drawables[0], drawables[1], drawables[2], drawables[3]);
        }
    }
}
